
layui.use(['form','layer','element','laydate','laytpl'], function () {

	initDayReport();

	initHourReport();

});

function initDayReport(){
	$.ajax({
		url: ctxPath+'report/dayDeposit',
		type: 'get',
		dataType: "json",
		success: function (data) {
			if(data.rel){
				console.log(data.result)
				initCharts(data.result.dayLabelList,data.result.dayDataList,'dayCanvas','每日下单统计图');
			}
		}
	});
}

function initHourReport(){
	$.ajax({
		url: ctxPath+'report/hourDeposit',
		type: 'get',
		dataType: "json",
		success: function (data) {
			if(data.rel){
				console.log(data.result)
				initCharts(data.result.timeLabelList,data.result.timeDataList,'hourCanvas','每小时下单统计图');
			}
		}
	});
}

function initCharts(labelList,dataList,el,title) {

	var config = {
		type: 'line',
		data: {
			labels: labelList,
			datasets: [{
				label: '订单数量',
				backgroundColor: window.chartColors.blue,
				borderColor: window.chartColors.blue,
				data: dataList,
				fill: false,
			}]
		},
		options: {
			responsive: true,
			title: {
				display: true,
				text: title
			},
			tooltips: {
				mode: 'index',
				intersect: false,
			},
			hover: {
				mode: 'nearest',
				intersect: true
			},
			scales: {
				xAxes: [{
					display: true,
					scaleLabel: {
						display: true,
						labelString: '时间'
					}
				}],
				yAxes: [{
					display: true,
					scaleLabel: {
						display: true,
						labelString: '下单人数'
					}
				}]
			}
		}
	};
	var ctx = document.getElementById(el).getContext('2d');
	new Chart(ctx, config);
}

